<?php

use App\Http\Controllers\CheckController;
use App\Http\Controllers\MCategoryController;
use App\Http\Controllers\PetCategoryController;
use App\Http\Controllers\PermissionGroupController;
use App\Http\Controllers\StoreController;
use App\Http\Controllers\SubAccountController;
use App\Http\Controllers\SubAccountRoleController;
use App\Http\Controllers\UploadController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::group(['middleware' => ['auth:sanctum']], static function () {
    Route::post('upload', [UploadController::class, 'upload'])->name('upload.upload');
    Route::group(['middleware' => ['mojito.permission']], static function() {
        Route::group(['prefix' => 'store'], static function () {
            Route::get('index', [StoreController::class, 'index'])->name('store.index');
            Route::post('add', [StoreController::class, 'add'])->name('store.add');
            Route::post('edit', [StoreController::class, 'edit'])->name('store.edit');
            Route::post('setStorePass', [StoreController::class, 'setStorePass'])->name('store.setStorePass');
            Route::get('index-by-auth', [StoreController::class, 'indexByAuth'])->name('store.index-by-auth');
            Route::post('login', [StoreController::class, 'login'])->name('store.login');
            Route::group(['middleware' => 'store'], static function () {
                Route::get('info', [StoreController::class, 'info'])->name('store.info');
            });
        });

        Route::group(['prefix' => 'check'], static function () {
            Route::get('store-index', [CheckController::class, 'storeIndex'])->name('check.store-index');
            Route::post('store', [CheckController::class, 'checkStore'])->name('check.store');
        });
        Route::group(['middleware' => 'api'], static function() {
            Route::apiResources([
                'role'       => 'RoleController',
                'admin-user' => 'AdminUserController',
            ]);
            Route::get('guard-name-roles/{guardName}', 'RoleController@guardNameRoles')->name('role.guard-name-roles');
            Route::get('guard-name-and-sub-for-permissions/{guardName}', [PermissionGroupController::class, 'guardNameAndSubForPermissions'])->name('permission-group.guard-name-and-sub-for-permission');
        });
        Route::group(['prefix' => 'sub-account-role'], static function () {
            Route::get('index', [SubAccountRoleController::class, 'index'])->name('sub-account-role.index');
            Route::post('add', [SubAccountRoleController::class, 'add'])->name('sub-account-role.add');
            Route::patch('edit/{id}', [SubAccountRoleController::class, 'edit'])->name('sub-account-role.edit');
            Route::delete('del/{id}', [SubAccountRoleController::class, 'del'])->name('sub-account-role.del');
            Route::get('guard-name-roles/{guardName}', [SubAccountRoleController::class, 'guardNameRoles'])->name('sub-account-role.guard-name-roles');
            Route::get('{id}/permissions', [SubAccountRoleController::class, 'permissions'])->name('sub-account-role.permissions');
            Route::put('{id}/permissions', [SubAccountRoleController::class, 'assignPermissions'])->name('sub-account-role.assign-permissions');
        });
        Route::group(['prefix' => 'sub-account'], static function() {
            Route::get('index', [SubAccountController::class, 'index'])->name('sub-account.index');
            Route::post('add', [SubAccountController::class, 'add'])->name('sub-account.add');
            Route::patch('edit/{id}', [SubAccountController::class, 'edit'])->name('sub-account.edit');
            Route::delete('del/{id}', [SubAccountController::class, 'del'])->name('sub-account.del');
            Route::get('{id}/roles/{provider}', [SubAccountController::class, 'roles'])->name('sub-account.roles');
            Route::put('{id}/roles/{provider}', [SubAccountController::class, 'assignRoles'])->name('sub-account.assign-roles');
        });
        Route::group(['prefix' => 'm-category'], static function() {
            Route::post('add', [MCategoryController::class, 'add'])->name('m-category.add');
            Route::post('edit', [MCategoryController::class, 'edit'])->name('m-category.edit');
            Route::post('del', [MCategoryController::class, 'del'])->name('m-category.del');
            Route::get('index', [MCategoryController::class, 'index'])->name('m-category.index');
        });

        Route::group(['prefix' => 'pet-category'], static function() {
            Route::post('add', [PetCategoryController::class, 'add'])->name('pet-category.add');
            Route::post('edit', [PetCategoryController::class, 'edit'])->name('pet-category.edit');
            Route::post('del', [PetCategoryController::class, 'del'])->name('pet-category.del');
            Route::get('index', [PetCategoryController::class, 'index'])->name('pet-category.index');
        });
    });
});
